# Contributor: Holger Jaekel <holger.jaekel@gmx.de>
# Maintainer: Holger Jaekel <holger.jaekel@gmx.de>
pkgname=draco
pkgver=1.5.7
pkgrel=1
pkgdesc="Library for compressing and decompressing 3D geometric meshes and point clouds"
url="https://google.github.io/draco/"
arch="all !s390x"  # s390x: segfault in tests
license="Apache-2.0"
makedepends="cmake samurai eigen-dev tinygltf-dev ghc-filesystem python3"
checkdepends="gtest-dev gtest-src"
subpackages="$pkgname-static $pkgname-tools $pkgname-dev"
source="draco-$pkgver.tar.gz::https://github.com/google/draco/archive/refs/tags/$pkgver.tar.gz
	0001-Fix-removal-of-build-dir-prefix-from-include-path.patch
	0002-Install-proper-CMake-targets.patch
	0003-Use-C-17-filesystem-library.patch
	0004-Set-DRACO_LIBRARIES-for-backwards-compatibility.patch
	0005-Fix-FTBFS-with-GCC-13.patch
	0006-Fix-tinygltf-FsCallbacks.patch
	0007-gtest.patch
	"

prepare() {
	default_prepare
	rm -rf third_party
}

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=ON \
		-DCMAKE_BUILD_TYPE=None \
		-DDRACO_TESTS="$(want_check && echo TRUE || echo FALSE)" \
		-DDRACO_TRANSCODER_SUPPORTED=ON \
		-DDRACO_EIGEN_PATH=/usr/include/eigen3 \
		-DDRACO_FILESYSTEM_PATH=/usr/include/ \
		-DDRACO_TINYGLTF_PATH=/usr/include \
		-DDRACO_GOOGLETEST_PATH=/usr \
		-DCMAKE_SKIP_RPATH=ON \
		$crossopts
	cmake --build build
}

check() {
	LD_LIBRARY_PATH="$builddir/build" ./build/draco_tests
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

tools() {
	amove usr/bin
}

sha512sums="
8b444744cdf12fb9d276916eb2ff0735cd1a6497b65b88813ec457fe2169db987db62e3db253a7d0f3ae7d45ae6502e8a9f8c0b81abde73e07b3bec69f9dc170  draco-1.5.7.tar.gz
fb38bbba62622ee803252f5b230a284f9717e2d1cc606849968425cf85678e72a6039e2fdaa2b52a6961364e9564165f253c6a20dacac107cca3561194384373  0001-Fix-removal-of-build-dir-prefix-from-include-path.patch
dfd1faa6e7a8e1775c0affcee513ecbf51f577dd5d3457a2a6d38ee9ca0f0ef9ad68844c33f3b9654ac7f980934c2fba8dcd587948fbaa252b36eaf0621e4b6e  0002-Install-proper-CMake-targets.patch
89fd902355e09f1bed3a91ed1a61825c1c32458e100b482a09edb549638922d6ee1d4f09c806d5145bd5f9238b2b611ff3394684ace5aadfaeb9d88b221839ba  0003-Use-C-17-filesystem-library.patch
46cb6d7f017e7842edc536141d926233db68cdfac3022e44bab665884a2ce5d043eb71a07a1a42657185f847fd714b92eb0c563560fd806b533549498c80553c  0004-Set-DRACO_LIBRARIES-for-backwards-compatibility.patch
47eff30c0a7641da525bf6f54dad65888ef69ec096236dd8c8ba9ece87da7a503a38869290656f08a1d1fc16b93c0eb8151260816333d58756a67eccd98e1aae  0005-Fix-FTBFS-with-GCC-13.patch
f7b2e882f1b95f4f1a85027c202a29b0046fbc5ee9de8a0e8a47fa29fad553b0f0d9281ece03b55be15b564d60c00d5ade9f7e1b2b4bd05c4ec7f3594dbb7049  0006-Fix-tinygltf-FsCallbacks.patch
612f1b3b57e6872d77747adc1a1ebec635eb02673a4fbb0218f66222805b98a27b471a9708bf1eeeaa9ba9b884fbbd3f9e411d9133b195f85a7fa91d3219cff7  0007-gtest.patch
"
